package com.rabbitmq.delayplugin.producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import static com.rabbitmq.delayplugin.config.RabbitMQConfig.*;

@Component
@Slf4j
public class RabbitMQDelayPluginProducer {
    @Resource
    RabbitTemplate rabbitTemplate;

    public void send(String message,int delay){
        log.info("当前时间:【{}】,发送消息:【{}】,类型:【{}】", LocalDateTime.now(),message,delay);
        rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME,DELAY_QUEUE_ROUTINGKEY,message,msg-> {
          msg.getMessageProperties().setDelay(delay);
          return msg;
        });
    }
}
